package com.weipai.springboot.module.controller;

import com.weipai.springboot.enums.RetCode;
import com.weipai.springboot.model.api.Response;
import com.weipai.springboot.module.service.SystemService;
import com.weipai.springboot.module.service.impl.BrandServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author songmengqiang
 * @create 2018-08-30 18:21
 * 
 * 系统管理类
 **/
@RestController
public class SystemController {

    private static final Logger log = LoggerFactory.getLogger(SystemController.class);
    
    @Autowired
    SystemService systemService;

    /**
     * 保存员工提成比例
     * @param type：类型--0员工提成，1技工提成
     * @param rate
     * @return
     */
    @GetMapping("/system/saveCommissionRate/{type}/{rate}")
    public Response saveCommissionRate(@PathVariable("type") Integer type, @PathVariable("rate") Integer rate){
        Response response = new Response();
        try {
            response =  systemService.saveCommissionRate(type, rate);
        } catch (Exception e) {
            log.error("role list with error {}", e);
            response.setCode(RetCode.REQUEST_ERROR);
        }
        return response;
    }

    /**
     * 根据类型获得比例
     * @param type：0员工提成，1技工提成
     * @return
     */
    @GetMapping("/system/getCommissionRateByType/{type}")
    public Response getCommissionRateByType(@PathVariable("type") Integer type){
        return systemService.getCommissionRateByType(type);
    }

    /**
     * 修改提成比例
     * @param id
     * @param rate
     * @return
     */
    @GetMapping("/system/updateCommissionRateById/{id}/{rate}")
    public Response updateCommissionRateById(@PathVariable("id") Integer id, @PathVariable("rate") Integer rate){
        return systemService.updateCommissionRateById(id, rate);
    }

    /**
     * 获取运费
     * @return
     */
    @GetMapping("/system/getFreight")
    public Response getFreight(){
        return systemService.getFreight();
    }

    /**
     * 修改运费
     * @param freightId：主键
     * @param fullPackage：满多少
     * @param freight：运费
     * @return
     */
    @GetMapping("/updateFreight/{freightId}/{fullPackage}/{freight}")
    public Response updateFreight(@PathVariable("freightId") Integer freightId,
                                  @PathVariable("fullPackage") Integer fullPackage,
                                  @PathVariable("freight") Integer freight){
        return systemService.updateFreight(freightId, fullPackage, freight);
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
